package com.geor.gcv.ict.train;

import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.ml.CvANN_MLP;
import org.opencv.ml.CvANN_MLP_TrainParams;

/**
 * 机器学习 ：神经网路实现类
 * 
 * @author Administrator
 *
 */
public class MlANN implements Ml {
	CvANN_MLP ann = new CvANN_MLP();

	@Override
	public void train(Mat trainData, Mat label,String out) {
		CvANN_MLP_TrainParams params = new CvANN_MLP_TrainParams();

		params.set_train_method(CvANN_MLP_TrainParams.BACKPROP);
		params.set_bp_dw_scale(0.1);
		params.set_bp_moment_scale(0.1);
		Mat layerSizes = Mat.eye(new Size(1, 900), CvType.CV_32S);
		
		ann.create(layerSizes);
		ann.train(trainData, label, new Mat(), new Mat(), params, 0);
		ann.save(out);

	}

	@Override
	public float predict(Mat sample) {
		Mat response = new Mat();
		return ann.predict(sample, response);
	}

	@Override
	public void load(String path) {
		ann.load("ann.xml");
	}

	@Override
	public boolean isSuccess() {
		// TODO Auto-generated method stub
		return false;
	}

}
